﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.OleDb;
using CIRDiagnoseDevice.DBManage;

namespace CIRDiagnoseDevice
{
    public partial class TestIndexConfig : DevExpress.XtraEditors.XtraForm
    {
        private TestRecordManage trm;
        public TestIndexConfig()
        {
            InitializeComponent();

            //this.lb_status.Visible = false; 
            //// TestConfig.ShowNewFolderButton = false;
            // TestConfig.ShowDialog();
            // if (TestConfig.ShowDialog() == DialogResult.OK)
            // {
            //     EXCELtoSQL ets = new EXCELtoSQL(TestConfig.FileName );
            //     GridviewExcelData.DataSource = ets.xsldata();
            //    // GridviewExcelData.DataBindings ;       //显示文件路径
            // }
            this.trm = new TestRecordManage();
        }
        /// <summary>
        /// 汇入新指标；将删掉以前的旧指标，并且立即使用此汇入指标
        /// </summary>
        public void huiruzhibiao()
        {
            System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
            if (fd.ShowDialog() == DialogResult.OK)
            {
                EXCELtoSQL ets = new EXCELtoSQL(fd.FileName);
                DataTable dt = ets.xsldataTestConfig();
                trm.DeleteSql("where defaultConfig=0", "tb_TestIndexConfig");
                trm.ExecuteSql("update tb_TestIndexConfig set usingflag=0 where usingflag=1 ");
                if (!trm.RestoreData(dt, "tb_TestIndexConfig"))
                {
                    MessageBox.Show("汇入标准不能有两条一样的分类和测试分组，请检查，科学计数单位无则填0.");
                    return;
                }
                GridviewExcelData.DataSource = dt;
            }
        }
        /// <summary>
        /// 使用默认指标
        /// </summary>
        public void shiyongmorenzhibiao()
        {
            trm.OpenDataBase();
            trm.ExecuteSql("update tb_TestIndexConfig set defaultConfig=1");
            MessageBox.Show("使用默认值表.设置成功");
            trm.CloseDataBase();
        }
        /// <summary>
        /// 使用汇入指标
        /// </summary>
        public void shiyonghuiruzhibiao()
        {
            trm.OpenDataBase();
            trm.ExecuteSql("update tb_TestIndexConfig set defaultConfig=0");
            MessageBox.Show("使用汇入指标,设置成功");
            trm.OpenDataBase();
        }
        private void TestConfig_HelpRequest(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 汇入修改默认指标(修改用户最低最高指标两个字段)
        /// </summary>
        public void xiugaizhibiao()
        {
            string message;
            System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
            if (fd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    EXCELtoSQL ets = new EXCELtoSQL(fd.FileName);
                    DataTable dt = ets.xsldataTestConfigUser();
                    trm.OpenDataBase();
                    if (trm.DataUpdateTestConfig(dt, 10))
                    {
                        message = "汇入成功";
                    }
                    else
                    {
                        message = "汇入失败";
                    } 
                }
                catch (Exception)
                {
                    message = "汇入文件资料有误， 请检查！";

                }
                trm.CloseDataBase();
                MessageBox.Show(message);
            }


        }




    }
}